/**
 * 
 */
package com.dingding.service.mall.dao.impl;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.Commodity;
import com.dingding.facade.mall.dto.CommodityInfo;
import com.dingding.facade.mall.sql.UserCommodityOrderSQL;
import com.dingding.service.mall.dao.ICommodityInfoDao;

/**
 * @ClassName: CommodityInfoDaoImpl
 * @Description:获取商品详情
 * @author zhouxuan
 */

@Component("commodityInfoDao")

public class CommodityInfoDaoImpl extends BaseDaoImpl<Commodity> implements ICommodityInfoDao {
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * @Title: getCommodityInfo
	 * @Description:获取商品详情
	 * @param @param
	 *            commodityId
	 * @param @returnCommodityInfo
	 * @author zhouxuan
	 */

	public CommodityInfo getCommodityInfo(String commodityId) {

		CommodityInfo commodityInfo = new CommodityInfo();
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(UserCommodityOrderSQL.GET_COMMODITY_INFO_SQL, commodityId);
		} catch (Exception e) {
			log.error("获取商品详情出错:CommodityInfoDaoImpl:getCommodityInfo()", e);
		}

		serResCommodityInfo(obj, commodityInfo);

		return commodityInfo;
	}

	/**
	 * 将obj转为bean
	 */
	public void serResCommodityInfo(Object[] obj, CommodityInfo commodityInfo) {
		if (obj != null && obj.length > 0) {
			commodityInfo.setPrice(Double.parseDouble(obj[0].toString()));
			commodityInfo.setDescript(obj[1].toString());
			commodityInfo.setName(obj[2].toString());
		}
	}
}
